package cn.wizzer.app.web.modules.controllers.user;

import cn.wizzer.app.sys.modules.services.SysParamService;
import cn.wizzer.app.user.modules.services.UserService;
import cn.wizzer.app.web.commons.filter.ApiTokenFilter;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.annotation.*;

/**
 * @author zl
 * @date 2020/8/6 14:09
 */
@IocBean
@At("/api/user/team")
public class ApiTeamController {

    @Inject
    @Reference
    private UserService userService;
    @Inject
    @Reference
    private SysParamService sysParamService;

    /**
     * 有效层级
     *
     * @return
     */
    @At
    @Ok("json")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result validLevel() {
        return Result.success().addData(sysParamService.fetch().getRebateValidLayer());
    }

    /**
     * 团队列表
     *
     * @return
     */
    @At
    @Ok("json:full")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result myTeam(@Param("level") Integer level,
                         @Param("timezone") String timezone,
                         @Param("startTime") long startTime,
                         @Param("endTime") long endTime,
                         @Param("pageNumber") int pageNumber,
                         @Param("pageSize") int pageSize) {
        return Result.success(userService.inviteList(Mvcs.getReq().getHeader("appid"), level, timezone, startTime, endTime, pageNumber, pageSize));
    }

    /**
     * 我的邀请
     *
     * @return
     */
    @At
    @Ok("json:full")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result myInvitation() {
        return Result.success(userService.myInvitation(Mvcs.getReq().getHeader("appid")));
    }

    /**
     * 邀请榜
     *
     * @return
     */
    @At
    @Ok("json:full")
    @Filters(@By(type = ApiTokenFilter.class))
    public Result invitationList(@Param("limit") Integer limit) {
        return Result.success(userService.invitationList(limit));
    }

}
